package common.view;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.event.ActionListener;

import javax.swing.JSeparator;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

public class GinView extends JPanel 
{
	private MaterialAdderView mAdder;
	private JTextField textFieldGinDate;
	private JTextField textFieldChalanDate;
	private JTextField tfchNo;
	private JTextField tfginNo;
	private JTextField tfvehicalNumber;
	private JTextField tfSendQty;
	private JTextField tfRecievedQty;
	private JTable table;
	private JButton btnGinDate;
	private JComboBox cbcbProjectName;
	private JComboBox cbcostCenterName;
	private JComboBox cbpoNumber;
	private JButton btnSave;
	private JButton btnChalanDate;
	
	public GinView() 
	{	
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		JLabel lblginDate = new JLabel("Gin Date :");
		lblginDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblginDate, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, lblginDate, 10, SpringLayout.WEST, this);
		add(lblginDate);
		
		textFieldGinDate = new JTextField();
		textFieldGinDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, textFieldGinDate, 6, SpringLayout.SOUTH, lblginDate);
		springLayout.putConstraint(SpringLayout.WEST, textFieldGinDate, 10, SpringLayout.WEST, this);
		add(textFieldGinDate);
		textFieldGinDate.setColumns(15);
		
		btnGinDate = new JButton("Cl");
		btnGinDate.setActionCommand("GinDate");
		btnGinDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, btnGinDate, 0, SpringLayout.NORTH, textFieldGinDate);
		springLayout.putConstraint(SpringLayout.WEST, btnGinDate, 6, SpringLayout.EAST, textFieldGinDate);
		add(btnGinDate);
		
		JLabel lblGinNo = new JLabel("Gin No :");
		springLayout.putConstraint(SpringLayout.NORTH, lblGinNo, 0, SpringLayout.NORTH, lblginDate);
		springLayout.putConstraint(SpringLayout.WEST, lblGinNo, 20, SpringLayout.EAST, btnGinDate);
		lblGinNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(lblGinNo);
		
		tfginNo = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, tfginNo, 0, SpringLayout.NORTH,textFieldGinDate);
		springLayout.putConstraint(SpringLayout.WEST, tfginNo, 0, SpringLayout.WEST,lblGinNo);
		tfginNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		add(tfginNo);
		tfginNo.setColumns(15);
		
		JLabel lblChalanDate = new JLabel("Chalan Date :");
		lblChalanDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblChalanDate, 10, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, lblChalanDate, 20, SpringLayout.EAST, tfginNo);
		add(lblChalanDate);
		
		textFieldChalanDate = new JTextField();
		textFieldChalanDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, textFieldChalanDate, 0, SpringLayout.NORTH,tfginNo);
		springLayout.putConstraint(SpringLayout.WEST, textFieldChalanDate, 0, SpringLayout.WEST, lblChalanDate);
		add(textFieldChalanDate);
		textFieldChalanDate.setColumns(15);
		
		btnChalanDate = new JButton("Cl");
		btnChalanDate.setActionCommand("ChalanDate");
		btnChalanDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, btnChalanDate, 0, SpringLayout.NORTH,textFieldChalanDate);
		springLayout.putConstraint(SpringLayout.WEST, btnChalanDate, 6, SpringLayout.EAST, textFieldChalanDate);
		add(btnChalanDate);
		
		JLabel lblChalanNo = new JLabel("Chalan No :");
		lblChalanNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblChalanNo, 0, SpringLayout.NORTH, lblChalanDate);
		springLayout.putConstraint(SpringLayout.WEST, lblChalanNo, 20, SpringLayout.EAST, btnChalanDate);
		add(lblChalanNo);
		
		tfchNo = new JTextField();
		tfchNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, tfchNo, 0, SpringLayout.NORTH, btnChalanDate);
		springLayout.putConstraint(SpringLayout.WEST, tfchNo, 0, SpringLayout.WEST, lblChalanNo);
		add(tfchNo);
		tfchNo.setColumns(15);
		
		JLabel lblProjectName = new JLabel("Project Name :");
		lblProjectName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblProjectName, 20, SpringLayout.SOUTH, textFieldGinDate);
		springLayout.putConstraint(SpringLayout.WEST, lblProjectName, 0, SpringLayout.WEST, lblginDate);
		add(lblProjectName);
		
		cbcbProjectName = new JComboBox();
		cbcbProjectName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		cbcbProjectName.setPreferredSize(new Dimension(200, 20));
		springLayout.putConstraint(SpringLayout.NORTH, cbcbProjectName, 6, SpringLayout.SOUTH, lblProjectName);
		springLayout.putConstraint(SpringLayout.WEST, cbcbProjectName, 0, SpringLayout.WEST, lblginDate);
		add(cbcbProjectName);
		
		JLabel lblCostCenter = new JLabel("Cost Center :");
		lblCostCenter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblCostCenter, 0, SpringLayout.NORTH, lblProjectName);
		springLayout.putConstraint(SpringLayout.WEST, lblCostCenter, 20, SpringLayout.EAST, cbcbProjectName);
		add(lblCostCenter);
		
		cbcostCenterName = new JComboBox();
		cbcostCenterName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		cbcostCenterName.setPreferredSize(new Dimension(200, 20));
		springLayout.putConstraint(SpringLayout.NORTH, cbcostCenterName, 0, SpringLayout.NORTH, cbcbProjectName);
		springLayout.putConstraint(SpringLayout.WEST, cbcostCenterName, 0, SpringLayout.WEST, lblCostCenter);
		add(cbcostCenterName);
		
		JLabel lblPurchaseOrder = new JLabel("Purchase Order Number");
		lblPurchaseOrder.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblPurchaseOrder, 0, SpringLayout.NORTH, lblProjectName);
		springLayout.putConstraint(SpringLayout.WEST, lblPurchaseOrder, 20, SpringLayout.EAST, cbcostCenterName);
		add(lblPurchaseOrder);
		
		cbpoNumber = new JComboBox();
		cbpoNumber.setPreferredSize(new Dimension(200, 20));
		cbpoNumber.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, cbpoNumber, 0, SpringLayout.NORTH, cbcostCenterName);
		springLayout.putConstraint(SpringLayout.WEST, cbpoNumber, 0, SpringLayout.WEST, lblPurchaseOrder);
		add(cbpoNumber);
		
		JLabel lblVehicalNo = new JLabel("Vehical No :");
		lblVehicalNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblVehicalNo, 0, SpringLayout.NORTH, lblginDate);
		springLayout.putConstraint(SpringLayout.WEST, lblVehicalNo, 20, SpringLayout.EAST, tfchNo);
		add(lblVehicalNo);
		
		tfvehicalNumber = new JTextField();
		tfvehicalNumber.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, tfvehicalNumber, 0, SpringLayout.NORTH, textFieldGinDate);
		springLayout.putConstraint(SpringLayout.WEST, tfvehicalNumber, 0, SpringLayout.WEST, lblVehicalNo);
		add(tfvehicalNumber);
		tfvehicalNumber.setColumns(15);
		
		JLabel lblSendQty = new JLabel("Send Quantity :");
		lblSendQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblSendQty, 0, SpringLayout.NORTH, lblProjectName);
		springLayout.putConstraint(SpringLayout.WEST, lblSendQty, 20, SpringLayout.EAST, cbpoNumber);
		add(lblSendQty);
		
		tfSendQty = new JTextField();
		tfSendQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, tfSendQty, 0, SpringLayout.NORTH, cbcbProjectName);
		springLayout.putConstraint(SpringLayout.WEST, tfSendQty, 0, SpringLayout.WEST, lblSendQty);
		add(tfSendQty);
		tfSendQty.setColumns(15);
		
		JLabel lblReceivedQty = new JLabel("Received Quantity :");
		lblReceivedQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, lblReceivedQty, 0, SpringLayout.NORTH, lblProjectName);
		springLayout.putConstraint(SpringLayout.WEST, lblReceivedQty, 20, SpringLayout.EAST, tfSendQty);
		add(lblReceivedQty);
		
		tfRecievedQty = new JTextField();
		tfRecievedQty.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, tfRecievedQty, 0, SpringLayout.NORTH, cbcbProjectName);
		springLayout.putConstraint(SpringLayout.WEST, tfRecievedQty, 0, SpringLayout.WEST, lblReceivedQty);
		add(tfRecievedQty);
		tfRecievedQty.setColumns(15);
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 10, SpringLayout.SOUTH, cbcbProjectName);
		springLayout.putConstraint(SpringLayout.WEST, separator, 10, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -10, SpringLayout.EAST, this);
		add(separator);
		
		btnSave = new JButton("Save");
		btnSave.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.SOUTH, btnSave, -10, SpringLayout.SOUTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnSave, 200, SpringLayout.WEST, this);
		add(btnSave);
		btnSave.setActionCommand("Save");
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 200, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.NORTH, btnSave);
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 10, SpringLayout.SOUTH, separator);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -10, SpringLayout.EAST, this);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null, null, null, null, null},
			},
			new String[] {
				"Sr. No.", "Material Name", "Specification", "Purchase Order Qty", "Send Qty", "Received Qty", "Rejected Qty"
			}
		));
		scrollPane.setViewportView(table);
		
		
		mAdder=new MaterialAdderView();
		springLayout.putConstraint(springLayout.WEST, mAdder, 10,springLayout.WEST, this);
		springLayout.putConstraint(springLayout.NORTH, mAdder, 10,springLayout.SOUTH, separator);
		springLayout.putConstraint(springLayout.EAST, mAdder, -10,springLayout.WEST, scrollPane);
		//springLayout.putConstraint(springLayout.SOUTH, mAdder, 0,springLayout.SOUTH,scrollPane);
		add(mAdder);
	}

	public JTextField getTfRecievedQty() {
		return tfRecievedQty;
	}

	public void setTfRecievedQty(JTextField tfRecievedQty) {
		this.tfRecievedQty = tfRecievedQty;
	}

	public JTextField getTfSendQty() {
		return tfSendQty;
	}

	public void setTfSendQty(JTextField tfSendQty) {
		this.tfSendQty = tfSendQty;
	}
	
	public JTextField getTfchNo() {
		return tfchNo;
	}

	public void setTfchNo(JTextField tfchNo) {
		this.tfchNo = tfchNo;
	}

	public JTextField getTfginNo() {
		return tfginNo;
	}

	public void setTfginNo(JTextField tfginNo) {
		this.tfginNo = tfginNo;
	}

	public JComboBox getCbcbProjectName() {
		return cbcbProjectName;
	}

	public void setCbcbProjectName(JComboBox cbcbProjectName) {
		this.cbcbProjectName = cbcbProjectName;
	}

	public JComboBox getCbcostCenterName() {
		return cbcostCenterName;
	}

	public void setCbcostCenterName(JComboBox cbcostCenterName) {
		this.cbcostCenterName = cbcostCenterName;
	}

	public JComboBox getCbpoNumber() {
		return cbpoNumber;
	}

	public void setCbpoNumber(JComboBox cbpoNumber) {
		this.cbpoNumber = cbpoNumber;
	}

	public JTextField getTfvehicalNumber() {
		return tfvehicalNumber;
	}

	public JTextField getTextFieldGinDate() {
		return textFieldGinDate;
	}

	public void setTextFieldGinDate(JTextField textFieldGinDate) {
		this.textFieldGinDate = textFieldGinDate;
	}

	public JTextField getTextFieldChalanDate() {
		return textFieldChalanDate;
	}

	public void setTextFieldChalanDate(JTextField textFieldChalanDate) {
		this.textFieldChalanDate = textFieldChalanDate;
	}

	public JButton getBtnGinDate() {
		return btnGinDate;
	}

	public void setBtnGinDate(JButton btnGinDate) {
		this.btnGinDate = btnGinDate;
	}

	public JButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}

	public JButton getBtnChalanDate() {
		return btnChalanDate;
	}

	public void setBtnChalanDate(JButton btnChalanDate) {
		this.btnChalanDate = btnChalanDate;
	}

	public void setTfvehicalNumber(JTextField tfvehicalNumber) {
		this.tfvehicalNumber = tfvehicalNumber;
	}

	public JTable getTable() {
		return table;
	}

	public void setTable(JTable table) {
		this.table = table;
	}

	public MaterialAdderView getmAdder() {
		return mAdder;
	}

	public void setmAdder(MaterialAdderView mAdder) {
		this.mAdder = mAdder;
	}
	public void actionlisteners(ActionListener al)
	{
		this.btnChalanDate.addActionListener(al);
		this.btnGinDate.addActionListener(al);
		btnSave.addActionListener(al);
	}
}
